package ReserveController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import Dao.ReserveDao;

public class Reservecancelform implements Controller {
	private ReserveDao reserveDao;

	public void setReserveDao(ReserveDao reserveDao) {
		this.reserveDao = reserveDao;
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {

		HashMap<String, String> data = new HashMap<String,String>();
		ArrayList room = new ArrayList();
		List<HashMap<String,String>> checkdata = null;
		String rooms[] = null;
		ModelAndView mav = new ModelAndView();
		String fail = "-1";
		
		data.put("RV_NAME", arg0.getParameter("member_name"));
		data.put("RV_NUM", arg0.getParameter("order_no"));
		
		checkdata = (List<HashMap<String,String>>)reserveDao.getCheckReserve(data);
		
		if(checkdata.size()<=0){
			mav.addObject("data",fail);
			mav.setViewName("reservecancel");
			return mav;
		}else{
			rooms = checkdata.get(0).get("RV_ROOM").split("/");
			for(int i=0; i<rooms.length; i++){
				room.add(reserveDao.getInfo(rooms[i]));
			}
			mav.addObject("room",room);
			mav.addObject("data",checkdata);
			mav.setViewName("reservecancelform");
			return mav;
		}
	}
}
